package com.regedit.aplicacion.adapters;

import java.util.ArrayList;

import com.regedit.aplicacion.R;
import com.regedit.aplicacion.R.drawable;
import com.regedit.aplicacion.R.id;
import com.regedit.aplicacion.models.Carro;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MiAdapter extends BaseAdapter {

	private ArrayList<Carro> mLista;
	private int mLayout;
	private Context mContext;

	public MiAdapter(Context context, ArrayList<Carro> lista, int layout) {
		mLista = lista;
		mLayout = layout;
		mContext = context;
	}

	@Override
	public int getCount() {

		return mLista.size();
	}

	@Override
	public Object getItem(int position) {

		return mLista.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Carro carro = (Carro) getItem(position);
		convertView = View.inflate(mContext, mLayout, null);
		TextView txtMarca = (TextView) convertView.findViewById(R.id.marca);
		txtMarca.setText(carro.getMarca());

		ImageView imagen = (ImageView) convertView.findViewById(R.id.imagen);
		if (position == 0) {
			imagen.setBackgroundDrawable(mContext.getResources().getDrawable(
					R.drawable.carro));
		} else if (position == 1) {
			imagen.setBackgroundDrawable(mContext.getResources().getDrawable(
					R.drawable.carro2));
		} else if (position == 2)
			imagen.setBackgroundDrawable(mContext.getResources().getDrawable(
					R.drawable.carro3));
		return convertView;
	}

}
